package edu.zhuoxun.blogserver.map;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.zhuoxun.blogserver.entity.Permission;
import edu.zhuoxun.blogserver.entity.Role;
import edu.zhuoxun.blogserver.entity.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermissionMapper extends BaseMapper<Permission> {
    @Select("select distinct p.* from user_role ur left join role_permission rp on ur.role_id = rp.role_id left join permission p on rp.permission_id = p.id where ur.user_id = #{id} and p.id is not null;")
    List<Permission> getPermissionsByUser(User user);
    @Select("select distinct p.* from role_permission rp left join permission p on rp.permission_id = p.id where rp.role_id = #{id} and p.id is not null;")
    List<Permission> getPermissionsByRole(Role role);
}
